<?php

/**
 * This is the model class for table "ham_account_transaction".
 *
 * The followings are the available columns in table 'ham_account_transaction':
 * @property integer $id
 * @property string $type
 * @property double $transaction_amount
 * @property integer $account_id
 * @property string $date_time
 * @property string $tran_cert
 *
 * The followings are the available model relations:
 * @property Account $account
 */
class AccountTransaction extends CActiveRecord
{
	/**
	 * Returns the static model of the specified AR class.
	 * @param string $className active record class name.
	 * @return AccountTransaction the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'ham_account_transaction';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('type, transaction_amount, account_id, date_time, tran_cert', 'required'),
			array('account_id', 'numerical', 'integerOnly'=>true),
			array('transaction_amount', 'numerical'),
			array('type', 'length', 'max'=>50),
			array('tran_cert', 'length', 'max'=>128),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('id, type, transaction_amount, account_id, date_time, tran_cert', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
			'account' => array(self::BELONGS_TO, 'Account', 'account_id'),
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'id' => 'ID',
			'type' => 'Type',
			'transaction_amount' => 'Transaction Amount',
			'account_id' => 'Account',
			'date_time' => 'Date Time',
			'tran_cert' => 'Tran Cert',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('id',$this->id);
		$criteria->compare('type',$this->type,true);
		$criteria->compare('transaction_amount',$this->transaction_amount);
		$criteria->compare('account_id',$this->account_id);
		$criteria->compare('date_time',$this->date_time,true);
		$criteria->compare('tran_cert',$this->tran_cert,true);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}
}